//
//  LSEmotionViewModel.swift
//  EmotionKeyboard
//
//  Created by lj on 15/9/12.
//  Copyright © 2015年 itcast. All rights reserved.
//

import UIKit

class LSEmotionViewModel: NSObject {
    
    /// 表情包数组
    lazy var emoticonPackages = [LSEmoticonPackages]()
    
    func loadEmotionPackages() {
        
        emoticonPackages.append(LSEmoticonPackages(dict: ["group_name_cn" : "最近"]))
        
        let path = NSBundle.mainBundle().pathForResource("emoticons.plist", ofType: nil, inDirectory: "Emoticons.bundle")
        
        let dict = NSDictionary(contentsOfFile: path!)
        
        let emoticonArray = dict!["packages"] as! [[String: AnyObject]]
        
        for infoDict in emoticonArray {
            let id = infoDict["id"] as! String
            
            let packagesPath = NSBundle.mainBundle().pathForResource("info.plist", ofType: nil, inDirectory: "Emoticons.bundle/" + id)
            
            let packageDict = NSDictionary(contentsOfFile: packagesPath!) as! [String: AnyObject]
            
            emoticonPackages.append(LSEmoticonPackages(dict: packageDict))
        }

    }

    /// 根据 indexPath 返回对应的表情模型
    func emoticon(indexpath:NSIndexPath) -> LSEmoticon {
        return emoticonPackages[indexpath.section].emoticons[indexpath.item]
    }

}
